<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
require_once("../change_page.php");
require_once 'market.action.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" charset= "utf-8 "/>
        <title>乐知家园</title>
        <script language="javascript">
            function getRealData(){
                location.href = "marketDownload.php?method=real&menu=download";
            }
            function getModifyData(){
                location.href = "marketDownload.php?method=modify&menu=download";
            }
            function search_key(){
                var key = document.getElementById("keyword").value;
                if(key==null||key==''){
                    alert("\u8bf7输入关键字");
                } else {
                    var page = document.getElementById("current_page").value;
                    location.href = "marketAll.php?keyword=" + key + "&page=" + page + "&menu=all";
                }
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <body>
        <br/>
        <form action="save.action.php?module=all" method="post">
            <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                <tr align="align">
                    <td>&nbsp;<input type="submit" value="保存" onclick="save()"/></td>
                    <td>搜索编号、名称 <input type="text" name="keywork" id="keyword" value="" /> <input type="button" value="搜索" onclick="search_key()" /></td>
                    <td bgcolor="#FFFFFF" align="right"><?php
                    $page_size = 100;
                    if (isset($_GET['page'])) {
                        $page = $_GET['page'];
                    } else {
                        $page = 0;
                    }
                    if (isset($_GET['keyword'])) {
                        $keyword = trim($_GET['keyword']);
                        $sql = "SELECT COUNT(*) AS total FROM t_product WHERE status = 1 AND (flashcode LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%')";
                    } else {
                        $sql = "SELECT COUNT(*) AS total FROM t_product WHERE status = 1";
                    }

                    $db = new DBC();
                    $total_num = $db->fetchData($sql);
                    if ($total_num != null) {
                        $total_num_product = $total_num[0]['total'];
                    }
                    $page_count = getPageSize($total_num_product, $page_size);
                    echo getPage("marketAll.php?menu=all", $page_count, $page);
                    ?></td>
                </tr>
            </table>
            <br/>
            <br/>
            <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr align="center">
                    <td bgcolor="#666666" width="10%"><span class="STYLE1">序号<input type="hidden" id="current_page" name="page" value="<?php echo $page; ?>"></input></span></td>
                    <td bgcolor="#666666" width="15%" align="left">&nbsp;<span class="STYLE1">编号</span></td>
                    <td bgcolor="#666666" width="55%" align="left">&nbsp;<span class="STYLE1">名称</span></td>
                    <td bgcolor="#666666" width="10%" align="left">&nbsp;<span class="STYLE1">排序</span></td>
                </tr>
                <?php
                $begin = $page * $page_size;
                if (isset($_GET['keyword'])) {
                    $keyword = trim($_GET['keyword']);
                    $sql = "SELECT flashcode AS code,name,num FROM t_product WHERE status = 1 AND (flashcode LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%') ORDER BY num LIMIT " . $begin . "," . $page_size;
                } else {
                    $sql = "SELECT flashcode AS code,name,num FROM t_product WHERE status = 1 ORDER BY num LIMIT " . $begin . "," . $page_size;
                }
                $num = $begin;
                $data = $db->fetchData($sql);
                if ($data != false && count($data) > 0) {
                    foreach ($data as $row) {
                        ?>
                        <tr>
                            <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" readonly="readonly" name="code[]" value="<?php echo $row['code']; ?>" style="width:100px;" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" readonly="readonly" name="name[]" value="<?php echo $row['name']; ?>" style="width:500px;" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="num[]" value="<?php echo $row['num']; ?>"  style="width:50px;"/>&nbsp;</td>
                        </tr>
                        <?php
                    }
                }
                ?>
            </table>
        </form>
    </body>
</html>
<?php
include_once '../footer.php';
?>